function [L] = SIGEloglik(pars_e)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%This is part of the set of files that accompany the article:       %
%Mankiw, N. Gregory and Ricardo Reis (2007) "Sticky Information in  %
%General Equilibrium," Journal of the European Economic Association,%
%forthcoming. See the appendix of the NBER or CEPR working paper    %
%versions for a detailed explanation of the algorithms.             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Please cite if you use the programs. I do not provide tech support.%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Last revised: August 30, 2006                                      %
%Written by: Ricardo Reis                                           %
%Input: set of parameters that are being estimated                  %
%Output: Minus log-likeliood value                                  %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

global T K N Y pars_c

%%%%STEP 1: RECOVER PARAMETERS %%%%%
pars=pars_c;
pars(4)=pars_e(1); pars(5)=pars_e(2);                          
pars(12)=pars_e(3); pars(13)=pars_e(4); pars(14)=pars_e(5);    
pars(15)=pars_e(6); pars(16)=pars_e(7); pars(17)=pars_e(8);    
pars(18)=pars_e(9); pars(19)=pars_e(10); pars(20)=pars_e(11);  
%Recall mapping from paranmeter names to pars vector
%beta=pars(1); psi=pars(2); theta=pars(3); nu=pars(4); gamma=pars(5);
%phiy=pars(6); phipi=pars(7); rho_m=pars(8); sigma_m=pars(9); rho_a=pars(10);
%sigma_a=pars(11); rho_g=pars(12); sigma_g=pars(13); rho_nu=pars(14);
%sigma_nu=pars(15); rho_gam=pars(16); sigma_gam=pars(17);
%delta=pars(18); omega=pars(19); lambda=pars(20);

%%%%STEP 2: SOLVE FOR MA REPRESENTATION %%%%%
[ma_m ma_a ma_g ma_nu ma_gam]=SIGEmafive(pars);

%%%%STEP 3: SOLVE FOR V MATRIX -- PARAMETERS INTO LL %%%%%
Sigma=diag([pars(9)^2 pars(11)^2 pars(13)^2 pars(15)^2 pars(17)^2]);
V=SIGEv(ma_m,ma_a,ma_g,ma_nu,ma_gam,Sigma);

%%%%STEP 4: CALCULATE LOG-LIKELIHOOD GIVEN DATA AND PARAMETERS %%%%%
L=SIGElogl(Y,V);
%disp(L); disp('At parameter values:'); disp(pars_e');
L = -L; %since optimization routines minimise rather than maximise
